/***********************************************
/gen auto by zuitools
***********************************************/
#include "mainActivity.h"

/*TAG:GlobalVariable全局变量*/
static ZKTextView* mTextViewLXPtr;
static ZKTextView* mTextViewTDSPtr;
static ZKButton* mButtonQCYSPtr;
static ZKButton* mButtonLeftPtr;
static ZKButton* mButtonRightPtr;
static ZKTextView* mTextView10Ptr;
static ZKTextView* mTextView9Ptr;
static ZKTextView* mTextView8Ptr;
static ZKTextView* mTextView7Ptr;
static ZKTextView* mTextView5Ptr;
static ZKTextView* mTextView4Ptr;
static ZKTextView* mTextView3Ptr;
static ZKCircleBar* mCircleBar2Ptr;
static ZKCircleBar* mCircleBar1Ptr;
static ZKTextView* mTextView6Ptr;
static ZKTextView* mTextViewCSPtr;
static ZKSlideWindow* mSlideWindow1Ptr;
static ZKButton* mButton17Ptr;
static ZKSeekBar* mSeekBar3Ptr;
static ZKButton* mButton16Ptr;
static ZKSeekBar* mSeekBar2Ptr;
static ZKSeekBar* mSeekBar1Ptr;
static ZKButton* mButton15Ptr;
static ZKButton* mButtonSDPtr;
static ZKTextView* mTextView2Ptr;
static ZKTextView* mTextView1Ptr;
static ZKButton* mButtonLockPtr;
static ZKButton* mButtonLXPtr;
static ZKButton* mButton14Ptr;
static ZKButton* mButton13Ptr;
static ZKButton* mButton500MLPtr;
static ZKButton* mButton300MLPtr;
static ZKButton* mButton230MLPtr;
static ZKButton* mButton150MLPtr;
static ZKTextView* mTextViewSDPtr;
static ZKTextView* mTextViewJBDHPtr;
static ZKButton* mButton12Ptr;
static ZKWindow* mWindow232Ptr;
static ZKButton* mButton11Ptr;
static ZKWindow* mWindow231Ptr;
static ZKButton* mButton10Ptr;
static ZKButton* mButton9Ptr;
static ZKButton* mButton8Ptr;
static ZKButton* mButton7Ptr;
static ZKButton* mButton6Ptr;
static ZKButton* mButton5Ptr;
static ZKButton* mButton4Ptr;
static ZKButton* mButton3Ptr;
static ZKWindow* mWindow26Ptr;
static ZKWindow* mWindow25Ptr;
static ZKWindow* mWindow24Ptr;
static ZKWindow* mWindow23Ptr;
static ZKWindow* mWindow22Ptr;
static ZKWindow* mWindow21Ptr;
static ZKWindow* mWindow2Ptr;
static ZKButton* mButton1Ptr;
static ZKWindow* mWindow1Ptr;
static ZKTextView* mTextviewD1Ptr;
static mainActivity* mActivityPtr;

/*register activity*/
REGISTER_ACTIVITY(mainActivity);

typedef struct {
	int id; // 定时器ID ， 不能重复
	int time; // 定时器  时间间隔  单位 毫秒
}S_ACTIVITY_TIMEER;

#include "logic/mainLogic.cc"

/***********/
typedef struct {
    int id;
    const char *pApp;
} SAppInfo;

/**
 *点击跳转window
 */
static SAppInfo sAppInfoTab[] = {
//  { ID_MAIN_TEXT, "TextViewActivity" },
};

/***************/
typedef bool (*ButtonCallback)(ZKButton *pButton);
/**
 * button onclick表
 */
typedef struct {
    int id;
    ButtonCallback callback;
}S_ButtonCallback;

/*TAG:ButtonCallbackTab按键映射表*/
static S_ButtonCallback sButtonCallbackTab[] = {
    ID_MAIN_ButtonQCYS, onButtonClick_ButtonQCYS,
    ID_MAIN_ButtonLeft, onButtonClick_ButtonLeft,
    ID_MAIN_ButtonRight, onButtonClick_ButtonRight,
    ID_MAIN_Button17, onButtonClick_Button17,
    ID_MAIN_Button16, onButtonClick_Button16,
    ID_MAIN_Button15, onButtonClick_Button15,
    ID_MAIN_ButtonSD, onButtonClick_ButtonSD,
    ID_MAIN_ButtonLock, onButtonClick_ButtonLock,
    ID_MAIN_ButtonLX, onButtonClick_ButtonLX,
    ID_MAIN_Button14, onButtonClick_Button14,
    ID_MAIN_Button13, onButtonClick_Button13,
    ID_MAIN_Button500ML, onButtonClick_Button500ML,
    ID_MAIN_Button300ML, onButtonClick_Button300ML,
    ID_MAIN_Button230ML, onButtonClick_Button230ML,
    ID_MAIN_Button150ML, onButtonClick_Button150ML,
    ID_MAIN_Button12, onButtonClick_Button12,
    ID_MAIN_Button11, onButtonClick_Button11,
    ID_MAIN_Button10, onButtonClick_Button10,
    ID_MAIN_Button9, onButtonClick_Button9,
    ID_MAIN_Button8, onButtonClick_Button8,
    ID_MAIN_Button7, onButtonClick_Button7,
    ID_MAIN_Button6, onButtonClick_Button6,
    ID_MAIN_Button5, onButtonClick_Button5,
    ID_MAIN_Button4, onButtonClick_Button4,
    ID_MAIN_Button3, onButtonClick_Button3,
    ID_MAIN_Button1, onButtonClick_Button1,
};
/***************/


typedef void (*SeekBarCallback)(ZKSeekBar *pSeekBar, int progress);
typedef struct {
    int id;
    SeekBarCallback callback;
}S_ZKSeekBarCallback;
/*TAG:SeekBarCallbackTab*/
static S_ZKSeekBarCallback SZKSeekBarCallbackTab[] = {
    ID_MAIN_SeekBar3, onProgressChanged_SeekBar3,
    ID_MAIN_SeekBar2, onProgressChanged_SeekBar2,
    ID_MAIN_SeekBar1, onProgressChanged_SeekBar1,
};


typedef int (*ListViewGetItemCountCallback)(const ZKListView *pListView);
typedef void (*ListViewobtainListItemDataCallback)(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index);
typedef void (*ListViewonItemClickCallback)(ZKListView *pListView, int index, int id);
typedef struct {
    int id;
    ListViewGetItemCountCallback getListItemCountCallback;
    ListViewobtainListItemDataCallback obtainListItemDataCallback;
    ListViewonItemClickCallback onItemClickCallback;
}S_ListViewFunctionsCallback;
/*TAG:ListViewFunctionsCallback*/
static S_ListViewFunctionsCallback SListViewFunctionsCallbackTab[] = {
};


typedef void (*SlideWindowItemClickCallback)(ZKSlideWindow *pSlideWindow, int index);
typedef struct {
    int id;
    SlideWindowItemClickCallback onSlideItemClickCallback;
}S_SlideWindowItemClickCallback;
/*TAG:SlideWindowFunctionsCallbackTab*/
static S_SlideWindowItemClickCallback SSlideWindowItemClickCallbackTab[] = {
    ID_MAIN_SlideWindow1, onSlideItemClick_SlideWindow1,
};


typedef void (*EditTextInputCallback)(const std::string &text);
typedef struct {
    int id;
    EditTextInputCallback onEditTextChangedCallback;
}S_EditTextInputCallback;
/*TAG:EditTextInputCallback*/
static S_EditTextInputCallback SEditTextInputCallbackTab[] = {
};

typedef void (*VideoViewCallback)(ZKVideoView *pVideoView, int msg);
typedef struct {
    int id; //VideoView ID
    bool loop; // 是否是轮播类型
    int defaultvolume;//轮播类型时,默认视频音量
    VideoViewCallback onVideoViewCallback;
}S_VideoViewCallback;
/*TAG:VideoViewCallback*/
static S_VideoViewCallback SVideoViewCallbackTab[] = {
};


mainActivity::mainActivity() {
	//todo add init code here
	mVideoLoopIndex = -1;
	mVideoLoopErrorCount = 0;
}

mainActivity::~mainActivity() {
  //todo add init file here
  // 退出应用时需要反注册
    EASYUICONTEXT->unregisterGlobalTouchListener(this);
    unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
    onUI_quit();
    mActivityPtr = NULL;
    mTextViewLXPtr = NULL;
    mTextViewTDSPtr = NULL;
    mButtonQCYSPtr = NULL;
    mButtonLeftPtr = NULL;
    mButtonRightPtr = NULL;
    mTextView10Ptr = NULL;
    mTextView9Ptr = NULL;
    mTextView8Ptr = NULL;
    mTextView7Ptr = NULL;
    mTextView5Ptr = NULL;
    mTextView4Ptr = NULL;
    mTextView3Ptr = NULL;
    mCircleBar2Ptr = NULL;
    mCircleBar1Ptr = NULL;
    mTextView6Ptr = NULL;
    mTextViewCSPtr = NULL;
    mSlideWindow1Ptr = NULL;
    mButton17Ptr = NULL;
    mSeekBar3Ptr = NULL;
    mButton16Ptr = NULL;
    mSeekBar2Ptr = NULL;
    mSeekBar1Ptr = NULL;
    mButton15Ptr = NULL;
    mButtonSDPtr = NULL;
    mTextView2Ptr = NULL;
    mTextView1Ptr = NULL;
    mButtonLockPtr = NULL;
    mButtonLXPtr = NULL;
    mButton14Ptr = NULL;
    mButton13Ptr = NULL;
    mButton500MLPtr = NULL;
    mButton300MLPtr = NULL;
    mButton230MLPtr = NULL;
    mButton150MLPtr = NULL;
    mTextViewSDPtr = NULL;
    mTextViewJBDHPtr = NULL;
    mButton12Ptr = NULL;
    mWindow232Ptr = NULL;
    mButton11Ptr = NULL;
    mWindow231Ptr = NULL;
    mButton10Ptr = NULL;
    mButton9Ptr = NULL;
    mButton8Ptr = NULL;
    mButton7Ptr = NULL;
    mButton6Ptr = NULL;
    mButton5Ptr = NULL;
    mButton4Ptr = NULL;
    mButton3Ptr = NULL;
    mWindow26Ptr = NULL;
    mWindow25Ptr = NULL;
    mWindow24Ptr = NULL;
    mWindow23Ptr = NULL;
    mWindow22Ptr = NULL;
    mWindow21Ptr = NULL;
    mWindow2Ptr = NULL;
    mButton1Ptr = NULL;
    mWindow1Ptr = NULL;
    mTextviewD1Ptr = NULL;
}

const char* mainActivity::getAppName() const{
	return "main.ftu";
}

//TAG:onCreate
void mainActivity::onCreate() {
	Activity::onCreate();
    mTextViewLXPtr = (ZKTextView*)findControlByID(ID_MAIN_TextViewLX);
    mTextViewTDSPtr = (ZKTextView*)findControlByID(ID_MAIN_TextViewTDS);
    mButtonQCYSPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonQCYS);
    mButtonLeftPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonLeft);
    mButtonRightPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonRight);
    mTextView10Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView10);
    mTextView9Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView9);
    mTextView8Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView8);
    mTextView7Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView7);
    mTextView5Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView5);
    mTextView4Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView4);
    mTextView3Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView3);
    mCircleBar2Ptr = (ZKCircleBar*)findControlByID(ID_MAIN_CircleBar2);
    mCircleBar1Ptr = (ZKCircleBar*)findControlByID(ID_MAIN_CircleBar1);
    mTextView6Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView6);
    mTextViewCSPtr = (ZKTextView*)findControlByID(ID_MAIN_TextViewCS);
    mSlideWindow1Ptr = (ZKSlideWindow*)findControlByID(ID_MAIN_SlideWindow1);if(mSlideWindow1Ptr!= NULL){mSlideWindow1Ptr->setSlideItemClickListener(this);}
    mButton17Ptr = (ZKButton*)findControlByID(ID_MAIN_Button17);
    mSeekBar3Ptr = (ZKSeekBar*)findControlByID(ID_MAIN_SeekBar3);if(mSeekBar3Ptr!= NULL){mSeekBar3Ptr->setSeekBarChangeListener(this);}
    mButton16Ptr = (ZKButton*)findControlByID(ID_MAIN_Button16);
    mSeekBar2Ptr = (ZKSeekBar*)findControlByID(ID_MAIN_SeekBar2);if(mSeekBar2Ptr!= NULL){mSeekBar2Ptr->setSeekBarChangeListener(this);}
    mSeekBar1Ptr = (ZKSeekBar*)findControlByID(ID_MAIN_SeekBar1);if(mSeekBar1Ptr!= NULL){mSeekBar1Ptr->setSeekBarChangeListener(this);}
    mButton15Ptr = (ZKButton*)findControlByID(ID_MAIN_Button15);
    mButtonSDPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonSD);
    mTextView2Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView2);
    mTextView1Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextView1);
    mButtonLockPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonLock);
    mButtonLXPtr = (ZKButton*)findControlByID(ID_MAIN_ButtonLX);
    mButton14Ptr = (ZKButton*)findControlByID(ID_MAIN_Button14);
    mButton13Ptr = (ZKButton*)findControlByID(ID_MAIN_Button13);
    mButton500MLPtr = (ZKButton*)findControlByID(ID_MAIN_Button500ML);
    mButton300MLPtr = (ZKButton*)findControlByID(ID_MAIN_Button300ML);
    mButton230MLPtr = (ZKButton*)findControlByID(ID_MAIN_Button230ML);
    mButton150MLPtr = (ZKButton*)findControlByID(ID_MAIN_Button150ML);
    mTextViewSDPtr = (ZKTextView*)findControlByID(ID_MAIN_TextViewSD);
    mTextViewJBDHPtr = (ZKTextView*)findControlByID(ID_MAIN_TextViewJBDH);
    mButton12Ptr = (ZKButton*)findControlByID(ID_MAIN_Button12);
    mWindow232Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window232);
    mButton11Ptr = (ZKButton*)findControlByID(ID_MAIN_Button11);
    mWindow231Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window231);
    mButton10Ptr = (ZKButton*)findControlByID(ID_MAIN_Button10);
    mButton9Ptr = (ZKButton*)findControlByID(ID_MAIN_Button9);
    mButton8Ptr = (ZKButton*)findControlByID(ID_MAIN_Button8);
    mButton7Ptr = (ZKButton*)findControlByID(ID_MAIN_Button7);
    mButton6Ptr = (ZKButton*)findControlByID(ID_MAIN_Button6);
    mButton5Ptr = (ZKButton*)findControlByID(ID_MAIN_Button5);
    mButton4Ptr = (ZKButton*)findControlByID(ID_MAIN_Button4);
    mButton3Ptr = (ZKButton*)findControlByID(ID_MAIN_Button3);
    mWindow26Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window26);
    mWindow25Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window25);
    mWindow24Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window24);
    mWindow23Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window23);
    mWindow22Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window22);
    mWindow21Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window21);
    mWindow2Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window2);
    mButton1Ptr = (ZKButton*)findControlByID(ID_MAIN_Button1);
    mWindow1Ptr = (ZKWindow*)findControlByID(ID_MAIN_Window1);
    mTextviewD1Ptr = (ZKTextView*)findControlByID(ID_MAIN_TextviewD1);
	mActivityPtr = this;
	onUI_init();
  registerProtocolDataUpdateListener(onProtocolDataUpdate);
  rigesterActivityTimer();
}

void mainActivity::onClick(ZKBase *pBase) {
	//TODO: add widget onClik code 
    int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
    for (int i = 0; i < buttonTablen; ++i) {
        if (sButtonCallbackTab[i].id == pBase->getID()) {
            if (sButtonCallbackTab[i].callback((ZKButton*)pBase)) {
            	return;
            }
            break;
        }
    }


    int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
    for (int i = 0; i < len; ++i) {
        if (sAppInfoTab[i].id == pBase->getID()) {
            EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
            return;
        }
    }

	Activity::onClick(pBase);
}

void mainActivity::onResume() {
	Activity::onResume();
	EASYUICONTEXT->registerGlobalTouchListener(this);
	startVideoLoopPlayback();
	onUI_show();
}

void mainActivity::onPause() {
	Activity::onPause();
	EASYUICONTEXT->unregisterGlobalTouchListener(this);
	stopVideoLoopPlayback();
	onUI_hide();
}

void mainActivity::onIntent(const Intent *intentPtr) {
	Activity::onIntent(intentPtr);
	onUI_intent(intentPtr);
}

bool mainActivity::onTimer(int id) {
	return onUI_Timer(id);
}

void mainActivity::onProgressChanged(ZKSeekBar *pSeekBar, int progress){

    int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
    for (int i = 0; i < seekBarTablen; ++i) {
        if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
            SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
            break;
        }
    }
}

int mainActivity::getListItemCount(const ZKListView *pListView) const{
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
            break;
        }
    }
    return 0;
}

void mainActivity::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
            break;
        }
    }
}

void mainActivity::onItemClick(ZKListView *pListView, int index, int id){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
            break;
        }
    }
}

void mainActivity::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
    int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
            SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
            break;
        }
    }
}

bool mainActivity::onTouchEvent(const MotionEvent &ev) {
    return onmainActivityTouchEvent(ev);
}

void mainActivity::onTextChanged(ZKTextView *pTextView, const std::string &text) {
    int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
            SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
            break;
        }
    }
}

void mainActivity::rigesterActivityTimer() {
    int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
    for (int i = 0; i < tablen; ++i) {
        S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
        registerTimer(temp.id, temp.time);
    }
}


void mainActivity::onVideoPlayerMessage(ZKVideoView *pVideoView, int msg) {
    int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SVideoViewCallbackTab[i].id == pVideoView->getID()) {
        	if (SVideoViewCallbackTab[i].loop) {
                //循环播放
        		videoLoopPlayback(pVideoView, msg, i);
        	} else if (SVideoViewCallbackTab[i].onVideoViewCallback != NULL){
        	    SVideoViewCallbackTab[i].onVideoViewCallback(pVideoView, msg);
        	}
            break;
        }
    }
}

void mainActivity::videoLoopPlayback(ZKVideoView *pVideoView, int msg, size_t callbackTabIndex) {

	switch (msg) {
	case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
		LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED\n");
    if (callbackTabIndex >= (sizeof(SVideoViewCallbackTab)/sizeof(S_VideoViewCallback))) {
      break;
    }
		pVideoView->setVolume(SVideoViewCallbackTab[callbackTabIndex].defaultvolume / 10.0);
		mVideoLoopErrorCount = 0;
		break;
	case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
		/**错误处理 */
		++mVideoLoopErrorCount;
		if (mVideoLoopErrorCount > 100) {
			LOGD("video loop error counts > 100, quit loop playback !");
            break;
		} //不用break, 继续尝试播放下一个
	case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
		LOGD("ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED\n");
        std::vector<std::string> videolist;
        std::string fileName(getAppName());
        if (fileName.size() < 4) {
             LOGD("getAppName size < 4, ignore!");
             break;
        }
        fileName = fileName.substr(0, fileName.length() - 4) + "_video_list.txt";
        fileName = "/mnt/extsd/" + fileName;
        if (!parseVideoFileList(fileName.c_str(), videolist)) {
            LOGD("parseVideoFileList failed !");
		    break;
        }
		if (pVideoView && !videolist.empty()) {
			mVideoLoopIndex = (mVideoLoopIndex + 1) % videolist.size();
			pVideoView->play(videolist[mVideoLoopIndex].c_str());
		}
		break;
	}
}

void mainActivity::startVideoLoopPlayback() {
    int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
    for (int i = 0; i < tablen; ++i) {
    	if (SVideoViewCallbackTab[i].loop) {
    		ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
    		if (!videoView) {
    			return;
    		}
    		//循环播放
    		videoLoopPlayback(videoView, ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED, i);
    		return;
    	}
    }
}

void mainActivity::stopVideoLoopPlayback() {
    int tablen = sizeof(SVideoViewCallbackTab) / sizeof(S_VideoViewCallback);
    for (int i = 0; i < tablen; ++i) {
    	if (SVideoViewCallbackTab[i].loop) {
    		ZKVideoView* videoView = (ZKVideoView*)findControlByID(SVideoViewCallbackTab[i].id);
    		if (!videoView) {
    			return;
    		}
    		if (videoView->isPlaying()) {
    		    videoView->stop();
    		}
    		return;
    	}
    }
}

bool mainActivity::parseVideoFileList(const char *pFileListPath, std::vector<string>& mediaFileList) {
	mediaFileList.clear();
	if (NULL == pFileListPath || 0 == strlen(pFileListPath)) {
        LOGD("video file list is null!");
		return false;
	}

	ifstream is(pFileListPath, ios_base::in);
	if (!is.is_open()) {
		LOGD("cann't open file %s \n", pFileListPath);
		return false;
	}
	char tmp[1024] = {0};
	while (is.getline(tmp, sizeof(tmp))) {
		string str = tmp;
		removeCharFromString(str, '\"');
		removeCharFromString(str, '\r');
		removeCharFromString(str, '\n');
		if (str.size() > 1) {
     		mediaFileList.push_back(str.c_str());
		}
	}
  LOGD("(f:%s, l:%d) parse fileList[%s], get [%d]files", __FUNCTION__,
      __LINE__, pFileListPath, int(mediaFileList.size()));
  for (std::vector<string>::size_type i = 0; i < mediaFileList.size(); i++) {
    LOGD("file[%u]:[%s]", ::size_t(i), mediaFileList[i].c_str());
  }
	is.close();

	return true;
}

int mainActivity::removeCharFromString(string& nString, char c) {
    string::size_type   pos;
    while(1) {
        pos = nString.find(c);
        if(pos != string::npos) {
            nString.erase(pos, 1);
        } else {
            break;
        }
    }
    return (int)nString.size();
}

void mainActivity::registerUserTimer(int id, int time) {
	registerTimer(id, time);
}

void mainActivity::unregisterUserTimer(int id) {
	unregisterTimer(id);
}

void mainActivity::resetUserTimer(int id, int time) {
	resetTimer(id, time);
}